﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Axis.Dao.Product;
using Axis.BusinessObject.Product;

namespace Sotipha.Web.Views.Home
{
    public partial class ucNEWESTPRODUCTS : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string Result = "";
            CProductDao coreProduct = new CProductDao();
            IList<CProduct> listProduct = coreProduct.GetProductByCondition("<InputValue Context=\"NewestProducts\"/>");
            string PatternImage = "<li>" +
                                "<div style=\"display: none; width: 200px;\" id=\"data_{0}\">" +
                                    "<div style=\"padding: 10px;\">" +
                                        "<img src=\"{1}\" width=\"100%\" /></div>" +
                                "</div>" +
                                "<a href=\"{2}\">" +
                                    "<img class=\"tooltip\" id=\"{0}\" src=\"{3}\" /></a> <span>" +
                                "</span></li>";

            string FristProduct = " <a class=\"im1\" href=\"{0}\"><img src=\"{1}\" /></a>";
            if (Session["lang"].ToString() == "vi")
                ltrNewestProducts.Text = "Sản phẩm mới nhất";
            if (listProduct != null)
                if (listProduct.Count > 0)
                {
                    var LinkFrist = BuildLink(listProduct[0]);
                    ltrFristProduct.Text = string.Format(FristProduct, LinkFrist, listProduct[0].Thumbnail);
                    for (int i = 1; i < 5 && i < listProduct.Count; i++)
                    {
                        var Link = BuildLink(listProduct[i]);
                        Result += string.Format(PatternImage, i, listProduct[i].Thumbnail, Link, listProduct[i].LargeImage);
                    }
                }

            ltrProduct.Text = Result;

        }
        public string BuildLink(CProduct Item)
        {
            string Result = "";
            switch (Item.ProductTypeID)
            {
                case 1:
                    Result = "../Towntalk/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 2:
                    Result = "../Lacquerware/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 3:
                    Result = "../Gifts/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 4:
                    Result = "../Sale/ProductDetail.aspx?ID=" + Item.ID;
                    break;
            }
            return Result;
        }
    }
}